<?php
/**
 * Author: lf
 * Blog: https://blog.feehi.com
 * Email: job@feehi.com
 * Created at: 2018-02-24 13:38
 */

use frontend\models\User;
use yii\widgets\DetailView;
use common\libs\Constants;
use api\models\VipAssignment;

/* @var $this yii\web\View */
/* @var $model \api\models\User */
?>
<?= DetailView::widget([
    'model'      => $model,
    'attributes' => [
        'id',
        [
            'attribute' => 'avatar',
            'format'    => 'raw',
            'value'     => function ($model) {
                /** @var  \backend\models\User $model */
                $avatar = '';
                if ( ! empty($model->avatar0)) {
                    $avatar = $model->avatar0->getImageUrl();
                }

                return "<img style='max-width:100px;max-height:100px' src='" . $avatar . "'>";
            }
        ],
        'username',
        'real_name',
        [
            'attribute' => "wx_avatar",
            'format'    => 'image'
        ],
        [
            'attribute' => "wx_name",
        ],
//        [
//            'attribute' => "wx_avatar",
//        ],
        [
            'attribute' => 'personCer',
            'value'     => function ($model) {
                return $model->personCer == 0 ? "否" : "是";
            }
        ],
        [
            'attribute' => 'businessCer',
            'value'     => function ($model) {
                return $model->businessCer == 0 ? "否" : "是";
            }
        ],
        'age',
        'description',
        [
            'attribute' => 'gender',
            'value'     => function ($model) {
                return Constants::getGender($model->gender);
            }
        ],
        'phone',
        [
            'attribute' => 'status',
            'value'     => function ($model) {

                return Constants::getUserStatus($model->status);
//                if ($model->status == User::STATUS_ACTIVE) {
//                    return Yii::t('app', 'Normal');
//                } elseif ($model->status == User::STATUS_DELETED) {
//                    return Yii::t('app', 'Disabled');
//                }
            }
        ],

        'created_at:datetime',
        'updated_at:datetime',
        [
            'label'  => "会员",
            'format' => "raw",
            'value'  => function ($model) {
                $string     = "";
                $assigments = VipAssignment::findAll(['user_id' => $model->id]);
                foreach ($assigments as $assigment) {
                    $string .= "名称：" . $assigment->itemName->description .
                               "  | 到期时间：" . date('Y-m-d', $assigment->expired_time) .
                               "  | 剩余次数：" . $assigment->availability_num .
                               "<br>";
                }

                return $string;
            }
        ],
    ],
]) ?>